package com.mk.common.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.junit.Test;


public class JDBCDemo {

	String url = "jdbc:mysql://127.0.0.1:3306/tduck?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&tinyInt1isBit=false";
	String username = "root";
	String password = "02141872";
	@Test
	public void test1() throws Exception {
        Statement stmt = null;
		Class.forName("com.mysql.cj.jdbc.Driver");
		Connection con = DriverManager.getConnection(url, username, password);
		
		System.out.println(con); //TODO
		
		stmt = con.createStatement();
        String sql;
        sql = "SELECT * FROM ac_user limit 1";
        ResultSet rs = stmt.executeQuery(sql);
        
        // 展开结果集数据库
        while(rs.next()){
            // 通过字段检索
            int id  = rs.getInt("id");
            String name = rs.getString("name");
            String login = rs.getString("account");

            // 输出数据
            System.out.print("ID: " + id);
            System.out.print(", 名称: " + name);
            System.out.print(", 登录名: " + login);
        }
	}
}
